package com.ict.controller;

import com.alibaba.fastjson.JSON;
import com.ict.model.InBoundOutBound;
import com.ict.service.InBoundOutBoundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by weiaquarius on 16/4/7.
 */
@Controller
@RequestMapping({"/inBoundOutBound"})
public class InBoundOutBoundController {
    @Autowired
    InBoundOutBoundService inBoundOutBoundService;

    /**
     * http://localhost:8080/inBoundOutBound/getInBoundOutBound.do?num=5
     * 根据send_time降序排列,返回最新的多条数据
     * @param map
     * @param num 所需数据的数量
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getInBoundOutBound.do",method = RequestMethod.GET)
    public String getInBoundOutBound(ModelMap map, @RequestParam int num) {

        List<InBoundOutBound> inBoundOutBound = inBoundOutBoundService.getInBoundOutBound(num);
        String jsonStr = JSON.toJSONString(inBoundOutBound);
        return jsonStr;
    }
}
